package rhc.discribute.node.connecter.impl.zookper.watchCallback;

import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher.Event.EventType;

import rhc.discribute.BaseComponent;
import rhc.discribute.node.connecter.impl.ZookperExecute;
import rhc.discribute.node.connecter.impl.zookper.WatchCallback;
import rhc.discribute.node.exception.CallbackException;

public class ReceiveMessageWatchCallback extends BaseComponent implements WatchCallback  {

	@Override
	public void executeCallback(WatchedEvent event, Object callbackData) throws CallbackException {
		
		ZookperExecute zkExecute=(ZookperExecute) callbackData;
		try {
			zkExecute.addMessageWatch();
			//节点删除是发送者删除
			if(event.getType() != EventType.NodeDeleted && event.getType() != EventType.NodeDataChanged){
				zkExecute.receiveMessage();
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

	@Override
	public boolean isSync() {
		return false;
	}

}
